package logic

import (
	"context"
	"rental/rentalrpc/rentalrpc"

	"rental/api/internal/svc"
	"rental/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProdcutAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProdcutAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProdcutAddLogic {
	return &ProdcutAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProdcutAddLogic) ProdcutAdd(req *types.ProdcutAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.RentalRpc.ProductAdd(l.ctx, &rentalrpc.ProductAddRequest{
		Image: req.Image,
		Name:  req.Name,
		Price: float32(req.Price),
		Stick: req.Stick,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "商品添加成功",
			Code:    200,
			Data:    add,
		}, nil
	}
}
